﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChartTools
{
    /// <summary>
    /// 面积图
    /// </summary>
    public class MSArea
    {
        private List<string> Labels;
        private List<MSAreaData> Datas;
        private string Function;
        private string ShowDivId;
        private string Title;
        private string XName;
        private string YName;
        public MSArea(List<string> pLabels, List<MSAreaData> pDatas, string pFunction, string pShowDivId, string pTitle, string pXName, string pYName)
        {
            Labels = pLabels;
            Datas = pDatas;
            Function = pFunction;
            ShowDivId = pShowDivId;
            Title = pTitle;
            XName = pXName;
            YName = pYName;
        }
        private MSArea()
        {

        }
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<chart bgColor='E9E9E9' outCnvBaseFontColor='666666' caption='" + Title + "'  xAxisName='" + XName + "' yAxisName='" + YName + "' numberPrefix='' showLabels='1' showValues='0' plotFillAlpha='70' numVDivLines='10' showAlternateVGridColor='1' AlternateVGridColor='e1f5ff' divLineColor='e1f5ff' vdivLineColor='e1f5ff'  baseFontColor='666666' canvasBorderThickness='1' showPlotBorder='1' plotBorderThickness='0'>");
            sb.Append("<categories>");
            foreach (string label in Labels)
            {
                sb.Append("<category label='" + label + "' />");
            }

            sb.Append("</categories>");
            for (int i = 0; i < Datas.Count; i++)
            {
                sb.Append("<dataset seriesName='" + Datas[i].LabelName + "' >");
                foreach (decimal data in Datas[i].Datas)
                {
                    sb.Append("<set value='" + data + "' />");
                }
                sb.Append("</dataset>");
            }
            sb.Append("</chart>");
            string str = sb.ToString();
            sb = new StringBuilder();
            sb.AppendLine("<script type=\"text/javascript\">");
            sb.Append("            function ");
            sb.Append(Function);
            sb.AppendLine("(){");
            sb.AppendLine("                var chart = new FusionCharts(\"/Content/FusionCharts/MSArea.swf\", \"ChartId\", \"100%\", \"290\", \"0\", \"0\");");
            sb.AppendLine("                chart.setXMLData(\"" + str + "\");");
            sb.AppendLine("                chart.render(\"" + ShowDivId + "\");");
            sb.AppendLine("             }");
            sb.AppendLine("        </script>");
            return sb.ToString();
        }
    }
    /// <summary>
    /// 面积图数据
    /// </summary>
    public class MSAreaData
    {
        public string LabelName { get; set; }

        public List<double> Datas { get; set; }
    }
}
